package lines.gameengine.stub;

import lines.gameengine.*;
import lines.gameengine.context.IFieldContext;

import java.util.Collection;
import java.util.List;

/**
 * @author vpotapenko
 */
public class StubField implements IField {

    private Cell[][] cells;

    public StubFieldContext context = new StubFieldContext();
    private FieldPoint selectedPoint;

    public StubField(int width, int height) {
        cells = new Cell[width][height];
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                cells[x][y] = new Cell(x, y);
            }
        }
    }

    @Override
    public void prepare() {
    }

    @Override
    public void reset() {
    }

    @Override
    public Cell getCell(int x, int y) {
        return cells[x][y];
    }

    @Override
    public Cell getCell(FieldPoint point) {
        return getCell(point.getX(), point.getY());
    }

    @Override
    public int getWidth() {
        return cells.length;
    }

    @Override
    public int getHeight() {
        return cells[0].length;
    }

    @Override
    public IFieldContext getContext() {
        return context;
    }

    @Override
    public boolean isValidPoint(int x, int y) {
        return x >= 0 && x < getWidth() &&
                y >=0 && y < getHeight();
    }

    @Override
    public boolean isValidPoint(FieldPoint point) {
        return point != null && isValidPoint(point.getX(), point.getY());
    }

    @Override
    public void clearCells(Collection<FieldPoint> points) {
        for (FieldPoint point : points) {
            getCell(point).setBall(null);
        }
    }

    @Override
    public void moveBall(FieldPoint startPoint, FieldPoint endPoint, List<FieldPoint> trace) {

    }

    @Override
    public void addNewBall(FieldPoint point, IBall ball) {
    }

    @Override
    public void setSelectedPoint(FieldPoint point) {
        this.selectedPoint = point;
    }

    @Override
    public FieldPoint getSelectedPoint() {
        return selectedPoint;
    }

    @Override
    public void addListener(IFieldListener l) {
    }

    @Override
    public void removeListener(IFieldListener l) {
    }
}
